// pages/message/chat/chat.js
// 获取全局APP
const app = getApp();

// 获取计时器函数
Page({
  /**
   * 页面的初始数据
   */
  data: {
    login: false,
    //输入框距离
    InputBottom: 0,
    roomId: 1,
    userInfo: {},
    content: '',
    groups: [{
      text: '点歌',
      value: 1
    }, ]
  }, 

  InputFocus(e) {
    this.setData({
      InputBottom: e.detail.height
    })
  },
  InputBlur(e) {
    // console.log(e);
    this.setData({
      InputBottom: 0,
      content: e.detail.value
    })
  },
  async submit() {
    var that = this;
    //已登录用户
    wx.showLoading({
      title: '信息发送',
    })
    const cht = app.globalData.cht
    const content = that.data.content
    // console.log(this.data.content);
    console.log(cht.data.chatList.push({
      "type": "man",
      "content": that.data.content,
    }))

    cht.setData({
      chatList: cht.data.chatList
    })
    that.setData({
      content: ''
    })
    wx.hideLoading();

    console.log("发送消息:", content)
    let data = {
      'content': content,
      'identity': app.globalData.chat_info['receiver_identity'],
      'identity_sender': app.globalData.chat_info['sender_identity'],
      'receiver_id': app.globalData.chat_info['receiver_id'],
      'sender_id': app.globalData.chat_info['sender_id']
    }
    app.formPost('/add_message?', data).then(res => {
      if (res['code']==1) {
        console.log('消息发送成功');
      }
    })
  },

})